/*
 * File   : includes/fileperm.h
 * Author : Nandakiran Kirubanandan
 * 
 * This file contains the macro definitions to test for 
 * file access permissions.
 * Parameters:
 * 	mode :  
 * 		Type : stat.st_mode
 * 		The parameter mode is obtained by 
 * 			struct stat filemode;
 * 			lstat(filename,&filemode);
 * 			mode=filemode.st_mode
 *	file : 
 *		Type : string	
 *		The name of the file
 *
 */
#ifndef __fileperm_h
#define __fileperm_h

#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#define OWNERREAD(mode) 	mode&S_IRWXU&S_IRUSR
#define OWNERWRITE(mode) 	mode&S_IRWXU&S_IWUSR
#define OWNEREXECUTE(mode) 	mode&S_IRWXU&S_IXUSR
#define GROUPREAD(mode) 	mode&S_IRWXG&S_IRGRP
#define GROUPWRITE(mode) 	mode&S_IRWXG&S_IWGRP
#define GROUPEXECUTE(mode) 	mode&S_IRWXG&S_IXGRP
#define OTHERSREAD(mode) 	mode&S_IRWXO&S_IROTH
#define OTHERSWRITE(mode) 	mode&S_IRWXO&S_IWOTH
#define OTHERSEXECUTE(mode) 	mode&S_IRWXO&S_IXOTH
#define DIRECTORY(mode)		S_ISDIR(mode)
#define READACCESS(file)	(access(file,R_OK)==0)
#define WRITEACCESS(file)	(access(file,W_OK)==0)
#define EXECACCESS(file)	(access(file,X_OK)==0)
#define SOMEACCESS(file)	(READACCESS(file)||WRITEACCESS(file)||(EXECACCESS(file)))
		
#endif
